package cn.com.shopec.erp.financing.dao.impl;

import java.math.BigInteger;
import java.util.List;

import org.hibernate.transform.Transformers;
import org.springframework.stereotype.Repository;
import cn.com.shopec.erp.common.orm.impl.HibernateEntityDao;
import cn.com.shopec.erp.common.page.PageFinder;
import cn.com.shopec.erp.common.page.PageQuery;
import cn.com.shopec.erp.common.utils.DateUtil;
import cn.com.shopec.erp.common.utils.LogicUtil;
import cn.com.shopec.erp.common.utils.StringUtil;
import cn.com.shopec.erp.financing.dao.ISupplierSettlementDao;
import cn.com.shopec.erp.financing.entity.SupplierSettlement;
import cn.com.shopec.erp.financing.vo.SupplierSettlementVo;

@Repository
public class SupplierSettlementDaoImpl extends HibernateEntityDao<SupplierSettlement>
		implements ISupplierSettlementDao {

	@Override
	public int updateSupplierSettlement(SupplierSettlement supplierSettlement) {
		String params = "";
		if (LogicUtil.isNotNull(supplierSettlement.getCheckState())) {
			if (StringUtil.isExist(params)) {
				params += ",check_state='" + supplierSettlement.getCheckState() + "'";
			} else {
				params += " check_state='" + supplierSettlement.getCheckState() + "'";
			}
		}
		if (LogicUtil.isNotNull(supplierSettlement.getCheckTime())) {
			if (StringUtil.isExist(params)) {
				params += ",check_time='"
						+ DateUtil.parseDate(supplierSettlement.getCheckTime(), DateUtil.TIMESTAMP_PATTERN) + "'";
			} else {
				params += " check_time='"
						+ DateUtil.parseDate(supplierSettlement.getCheckTime(), DateUtil.TIMESTAMP_PATTERN) + "'";
			}
		}
		if (LogicUtil.isNotNull(supplierSettlement.getUpdateTime())) {
			if (StringUtil.isExist(params)) {
				params += ",update_time='"
						+ DateUtil.parseDate(supplierSettlement.getUpdateTime(), DateUtil.TIMESTAMP_PATTERN) + "'";
			} else {
				params += " update_time='"
						+ DateUtil.parseDate(supplierSettlement.getUpdateTime(), DateUtil.TIMESTAMP_PATTERN) + "'";
			}
		}
		if (StringUtil.isExist(supplierSettlement.getOperatorId())) {
			if (StringUtil.isExist(params)) {
				params += ",operator_id='" + supplierSettlement.getOperatorId() + "'";
			} else {
				params += " operator_id='" + supplierSettlement.getOperatorId() + "'";
			}
		}
		if (StringUtil.isExist(params)) {
			String sql = "update tbl_supplier_settlement set " + params + " where settlement_id='"
					+ supplierSettlement.getSettlementId() + "'";
			return this.createSQLQuery(sql).executeUpdate();
		} else {
			return 0;
		}
	}

}
